<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib uri="http://displaytag.sf.net" prefix="display" %>
<%@ taglib prefix="sjt" uri="/struts-jquery-tree-tags"%>
<%@ taglib prefix="sx" uri="/struts-dojo-tags" %> 
<html>
<head>
<title>Welcome</title>
<link rel="stylesheet" href="../../WEB-INF/css/style.css" type="text/css" />
<style>
	#folio ul li { width:200px; margin:15px 0 0 0;}
	#folio li { list-style-type:none; text-align: left;}
	#folio1 ul li { margin:25px 0 0 0;}
	#folio1 li { list-style-type:none; text-align: left;} 
</style>
<%-- <sx:head parseContent="true"/> --%>
<sx:head/>
<script type="text/javascript">
function treeNodeSelected(arg) {
	// alert("id["+arg.source.widgetId+"], name["+ arg.source.title+ "] selected");
	dojo.byId("id").value = arg.source.widgetId;
	dojo.byId("name").value = arg.source.title;
	dojo.byId("url").value = arg.source.value;
	dojo.byid("parentId").value = arg.source.widgetId;
}
			
function treeNodeExpanded(arg) {
	// alert("id["+arg.source.widgetId+"], name["+ arg.source.title+ "] expanded");
}

function treeNodeCollapsed(arg) {
	// alert("id["+arg.source.widgetId+"], name["+ arg.source.title+ "] collapsed");
}

function save(data, type, request) {
				if(type == "load") {
					dojo.byId("name").value = "";
				}
			}
			
//			function edit(data, type, request) {
//				alert("In edit(...)")
							//if(type == "before") {
			//					var id = data.split("_")[1];
			//
			//					var tr = dojo.byId("row_"+id);
			//					var tds = tr.getElementsByTagName("td");
			
//								dojo.byId("id").value = "<s:property value="id" />";
//								dojo.byId("name").value = "<s:property value="name" />"
								//dojo.byId("lastName").value = dojo.string.trim(dojo.dom.textContent(tds[1]));
							//}
//						}
			


//dojo.addOnLoad(function() {                
//    var t = dojo.widget.byId('menuTree');
//    dojo.event.topic.subscribe(t.eventNames.expand, treeNodeExpanded);                
//    dojo.event.topic.subscribe(t.eventNames.collapse, treeNodeCollapsed);
	
//    var s = t.selector;   
			

//});
</script>
</head>
<body>
<script type="text/javascript">
			// alert('execute dojo.addOnLoad!');
			dojo.addOnLoad(function() {                
			    var t = dojo.widget.byId('menuTree');
			    dojo.event.topic.subscribe(t.eventNames.expand, treeNodeExpanded);                
			    dojo.event.topic.subscribe(t.eventNames.collapse, treeNodeCollapsed);
			    //dojo.event.topic.subscribe("/treeSelected", treeNodeSelected);
			    
			    //dojo.event.topic.subscribe("/save", save);
			    //dojo.event.topic.subscribe("/edit", edit);
			    var s = t.selector;   
		        dojo.event.connect(s, 'select', 'treeNodeSelected');     
		
		    });
</script>

<div id="tree">
  <s:if test="rootNodes.size > 0">
    <s:iterator value="rootNodes" var="rootNode">
      
      
      
      <sx:tree 
		    id="menuTree"
		    rootNode="rootNode"
		    childCollectionProperty="childMenus"
		    nodeIdProperty="id"
		    nodeTitleProperty="name" 
		    value="url">        
       </sx:tree>
      </s:iterator>
  </s:if>
</div>
	<%-- <h2>Howdy, <s:property value="username" />...!</h2><br /> --%>

	<s:form namespace="/login">
	<s:if test="%{legalEntity == null}">
	<%-- <s:hidden name="partners" value="%{partners}" /> --%>
		<display:table export="true" id="data" name="partners" requestURI="/login.action" pagesize="10" >
			<display:setProperty name="paging.banner.placement" value="bottom" />			
			<display:setProperty name="basic.empty.showtable" value="false" />
			<display:setProperty name="sort.amount" value="page" />
			<display:setProperty name="basic.msg.empty_list_row" value="" />
			<display:setProperty name="basic.msg.empty_list" value="" />
			<display:setProperty name="paging.banner.no_items_found" value="" />
			<display:setProperty name="paging.banner.one_item_found" value="" />
			<display:setProperty name="paging.banner.all_items_found" value="" />
			<display:setProperty name="paging.banner.some_items_found" value="" />
			<display:setProperty name="paging.banner.onepage" value="" />
			<%-- <display:setProperty name="export.banner" value="" /> --%>
			<display:setProperty name="export.types" value="csv excel xml pdf" />
			<display:setProperty name="export.csv.include_header" value="csv excel xml pdf" />
			<display:setProperty name="export.excel.include_header" value="csv excel xml pdf" />
			<display:setProperty name="export.xml.include_header" value="csv excel xml pdf" />
			<display:setProperty name="export.pdf.include_header" value="csv excel xml pdf" />
			<display:setProperty name="export.excel" value="true" />
			<display:setProperty name="export.csv" value="true" />
			<display:setProperty name="export.pdf" value="true" />
			<display:setProperty name="export.xml" value="true" />
			<display:setProperty name="export.excel.filename" value="xxx.xls" />
			<display:setProperty name="export.pdf.filename" value="xxx.pdf" />
			<display:setProperty name="export.csv.filename" value="xxx.csv" />
			<display:setProperty name="export.xml.filename" value="xxx.xml" />
			<display:setProperty name="export.amount" value="list" />
			<display:setProperty name="export.decorated" value="true" />
			<%-- <display:column property="partner.businessname" title="businessname" sortable="true"
				url="/login.action" paramId="businessname" paramProperty="partner.businessname">
				<s:url id="updateUrl" action="login.action">
                     <s:param name="id" value="partner.businessname" />
                 </s:url>
                 <s:param name="forenames" value="partner.forenames" />
			</display:column> --%>
			<display:column property="partner.link" title="Businessname" sortable="true" style="text-align:center;"/>
			<display:column property="partner.forenames" title="Forename" sortable="true" style="text-align:center;"/>
			<display:column property="partner.surnames" title="Surname" sortable="true" style="text-align:center;"/>
		</display:table>
		<sjt:tree id="Registrations" title="Registrations" openAllOnLoad="false" jstreetheme="ajax">
			<sjt:tree id="New submissions" rootNode="Registrations" title="New submissions"></sjt:tree>
			<sjt:tree id="Submissions In-progress" rootNode="Registrations" title="Submissions In-progress"></sjt:tree>
		</sjt:tree>
		<table border="1">
			<tbody>
				<tr>
					<td>
						<ul id="folio">
							<li><strong>Registrations</strong>
								<ul id="folio">
									<li>New submissions</li>
									<li>Submissions Inprogress</li>
								</ul>
							</li>
						</ul>
						<ul id="folio">
							<li><strong>Variations</strong></li>
						</ul>
					</td>
					<td align="center">
						<ul id="folio1">
							<li>&nbsp;</li>
							<li>&nbsp;</li>
							<li></li>
							<li><a href="http://google.com"><strong>1</strong></a></li>
						</ul>
						<ul id="folio1">
							<li><a href="http://google.com"><strong>1</strong></a></li>
							<li>&nbsp;</li>
							<li><a href="http://google.com"><strong>1</strong></a></li>
						</ul>
					</td>
				</tr>
			</tbody>
		</table>
		<%-- <sjt:tree id="treeStatic" openAllOnLoad="false" droppable="true" jstreetheme="ajax">
                <sjt:treeItem title="Struts2" targets="head1,head2,head3,head4"  >
                        <sjt:treeItem id="head1" title="General">
                                <sjt:treeItem title="Struts2" href="http://struts.apache.org/2.x/index.html"/>
                                <sjt:treeItem title="Struts2 @ Facebook" href="http://www.facebook.com/pages/Struts2-Users/103890046351798"/>
                        </sjt:treeItem>
                        <sjt:treeItem id="head2" title="Plugins">
                                <sjt:treeItem title="Struts2 Plugins" href="https://cwiki.apache.org/S2PLUGINS/home.html"/>
                                <sjt:treeItem title="Struts2 jQuery Plugin" href="http://code.google.com/p/struts2-jquery/"/>
                                <sjt:treeItem title="Struts2 Full Hibernate Plugin" href="http://code.google.com/p/full-hibernate-plugin-for-struts2/"/>
                        </sjt:treeItem>
                        <sjt:treeItem id="head3" title="Blogs">
                                <sjt:treeItem title="Struts2 jQuery News" href="http://www.jgeppert.com/category/java/struts2-jquery/"/>
                        </sjt:treeItem>
                        <sjt:treeItem id="head4" title="AJAX Links">
                                        <s:url id="ajax1" value="/ajax1.action"/>
                                <sjt:treeItem title="Ajax 1" href="%{ajax1}" targets="result"/>
                                        <s:url id="ajax2" value="/ajax2.action"/>
                                <sjt:treeItem title="Ajax 2" href="%{ajax2}" targets="result" effect="highlight" effectDuration="2500"/>
                                        <s:url id="ajax3" value="/ajax3.action"/>
                                <sjt:treeItem title="Ajax 3" href="%{ajax3}" targets="result" onBeforeTopics="beforeLink" onCompleteTopics="completeLink"/>
                                        <s:url id="ajax4" value="/ajax4.action"/>
                                <sjt:treeItem title="Ajax 4" href="%{ajax4}" targets="result" effect="bounce" effectDuration="1000"/>
                        </sjt:treeItem>
                </sjt:treeItem>
        </sjt:tree> --%>
        <%-- <sx:tree id="tree" label="Root" title="Root" href="http://www.google.com">
        	<sx:treenode label="treeNode1" title="treeNode1" ></sx:treenode>
        	<sx:treenode label="treeNode2" title="treeNode2"></sx:treenode>
        	<sx:treenode label="treeNode3" title="treeNode3"></sx:treenode>
        	<sx:treenode label="treeNode4" title="treeNode4"></sx:treenode>
        	<sx:treenode label="treeNode5" title="treeNode5"></sx:treenode>
        </sx:tree>
        	<a href="#" style="font-size:12px" onclick="expand();">Expand</a> 
        	<a href="#" style="font-size:12px" onclick="collapse();">Collapse</a>
			<sx:tree id="group" rootNode="contactGroupNode" nodeTitleProperty="name"
 				nodeIdProperty="id" childCollectionProperty="children" onclick="nodeClick(this);">
		 			<sx:treenode label="treeNode1" title="treeNode1" />
		        	<sx:treenode label="treeNode2" title="treeNode2"/>
		        	<sx:treenode label="treeNode3" title="treeNode3"/>
		        	<sx:treenode label="treeNode4" title="treeNode4"/>
		        	<sx:treenode label="treeNode5" title="treeNode5"/>
 			</sx:tree> --%>
		<%-- <table align="center">
			<thead>
				<tr>
					<th>Name</th>
					<th>Action</th>
				</tr>
			</thead>
			<tbody>
				<s:iterator value="partners" var="partner" status="stat">
					<tr>
						<td><s:a method="edit" namespace="/login"><s:property value="partner.businessName"/>&nbsp;<s:property value="partner.forenames"/><s:param name="id" value="partner.legal_entity_id"/></s:a></td>
						<td><s:a method="delete" namespace="/login">Delete<s:param name="id" value="partner.legal_entity_id"/></s:a></td>
					</tr>s
				</s:iterator>
				<tr>
					<td colspan="3" align="left">
						<s:submit method="add" key="label.add" />
					</td>
				</tr>
			</tbody>
		</table> --%>
		<%-- <s:property value="%{#context['struts.actionMapping']}" /> --%>
	</s:if>
	<s:elseif test="legalEntity != null">
		<table align="center">
			<tbody>
				<tr>
					<td><s:textfield name="businessName" key="label.businessname" value="%{legalEntity.businessname}" size="20" /></td>
					<td><s:textfield name="forename" key="label.forename" value="%{legalEntity.forenames}"  size="20" /></td>
					<td><s:textfield name="surname" key="label.surname" value="%{legalEntity.surnames}" size="20" /></td>
				</tr>
				<tr>
					<td>
						<s:submit method="back" key="label.back" action="login.action">
							<s:param name="businessname" value=""/>
							<s:param name="legal_entity_id" value=""/>
						</s:submit>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<s:submit method="edit" key="label.update" action="login.action">
							<s:hidden name="id" value="%{legalEntity.legal_entity_id}" />
						</s:submit>
					</td>
				</tr>
			</tbody>
		</table>
	</s:elseif>
	<s:elseif test="%{#context['struts.actionMapping'].method=='add'}">
		<table align="center">
			<tbody>
				<tr>
					<td><s:textfield name="businessName" key="label.businessname" size="20" /></td>
					<td><s:textfield name="forename" key="label.forename" size="20" /></td>
					<td><s:textfield name="surname" key="label.surname" size="20" /></td>
				</tr>
				<tr>
					<td colspan="3" align="right">
						<s:submit method="add" key="label.add" />
					</td>
				</tr>
			</tbody>
		</table>
	</s:elseif>
</s:form>
</body>
</html>
